﻿using Romantics.Domain;
using Romantics.Domain.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Romantics.Models
{
    public class HikeViewModel
    {
        public static HikeViewModel Planed(IDomainRepository _domainRepository, int p, Category category = null, Region region = null)
        {
            int pageSize = 5;
            HikeViewModel view = new HikeViewModel();
            view.Options = _domainRepository.Options();
            view.Hikes = _domainRepository.PlannedHikes(p - 1, pageSize, category, region);
            view.TotalPages = _domainRepository.TotalPlannedHikes(category, region) / pageSize;
            view.CurrentPage = p;
            return view;
        }

        public static HikeViewModel Archive(IDomainRepository _domainRepository, int? year, int p, Category category = null, Region region = null)
        {
            int pageSize = 5;
            HikeViewModel view = new HikeViewModel();
            view.Options = _domainRepository.Options();
            view.Hikes = _domainRepository.PreviousHikes(p - 1, pageSize, year, category, region);
            view.TotalPages = _domainRepository.TotalPreviousHikes(year, category, region) / pageSize;
            view.CurrentPage = p;
            view.CurrentYear = year;
            return view;
        }

        public static HikeViewModel Photos(IDomainRepository _domainRepository, int? year, int p, Category category = null, Region region = null)
        {
            int pageSize = 10;
            HikeViewModel view = new HikeViewModel();
            view.Options = _domainRepository.Options();
            view.PhotoAlbums = _domainRepository.PhotoAlbums(p - 1, pageSize, year, category, region);
            view.TotalPages = _domainRepository.TotalPhotoAlbums(year, category, region) / pageSize;
            view.CurrentPage = p;
            view.CurrentYear = year;
            return view;
        }

        public static HikeViewModel GetPhotoAlbum(IDomainRepository _domainRepository, int id, string mode, int p)
        {
            HikeViewModel view = new HikeViewModel();
            view.Options = _domainRepository.Options();
            view.PhotoAlbum = _domainRepository.PhotoAlbum(id);
            view.PhotoAlbum.Options = view.Options;
            view.TotalPages = _domainRepository.PhotoAlbumItemsCount(id) / 20;
            view.CurrentPage = p;
            view.Mode = mode;
            return view;
        }

        public static HikeViewModel GetPhotoAlbumItem(IDomainRepository _domainRepository, int id)
        {
            HikeViewModel view = new HikeViewModel();
            view.Options = _domainRepository.Options();
            view.PhotoAlbumItem = _domainRepository.PhotoAlbumItem(id);
            view.PhotoAlbumItem.Options = view.Options;
            view.TotalPages = 1;
            view.CurrentPage = 1;
            return view;
        }

        public IList<Hike> Hikes { get; private set; }
        public PhotoAlbum PhotoAlbum { get; private set; }
        public PhotoAlbumItem PhotoAlbumItem { get; private set; }
        public IList<PhotoAlbum> PhotoAlbums { get; private set; }
        public int TotalPages { get; private set; }
        public int CurrentPage { get; private set; }
        public int? CurrentYear { get; private set; }
        public string Mode { get; private set; }
        public Options Options { get; private set; }
    }
}